var Intercept = function() {
	var _isJqueryLoaded=false;
	var _listOfElements = Object(); 
	var _localTestCommandFile="http://localhost/FireFoxAuto/tempTest.txt?"+new Date();
	function _init(){
		try{
			//_addJSNode(null, 'file:///C:/Code/Dev/WebAutomation/WebAutomation/WebAutomation/Browsers/FireFox/GMScripts/jquery-1.7.2.min.js');
			var GM_JQ = document.createElement('script');
			GM_JQ.src = 'http://code.jquery.com/jquery.min.js';
			GM_JQ.type = 'text/javascript';
			document.getElementsByTagName('head')[0].appendChild(GM_JQ);
			GM_wait();
			
		}catch(e){
			alert("Error:"+e);
		}
	}

	function GM_wait() {
			if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
		else {
			$ = unsafeWindow.jQuery; _jqueryLoaded(); 
		}
	}

	function _sleep(ms)
	{
		var dt = new Date();
		dt.setTime(dt.getTime() + ms);
		while (new Date().getTime() < dt.getTime());
	}

	 
	// All your GM code must be inside this function
	function _jqueryLoaded() {
		
		_isJqueryLoaded=true;
		try{
			_getHtmlTextBoxes();
			var cmd="q:cat";
			GM_xmlhttpRequest({
			  method: "GET",
			  url: _localTestCommandFile,
			  onload: function(response) {
				cmd=response.responseText;
				var objArray = cmd.split(':'); 
				_sleep(5000);
				_processCommand(objArray[0],objArray[1],objArray[2]);
			  }
			});
			

		}catch(e){
			alert("Error _getHtmlTextBox:"+e);
		}
	}


	function _processCommand(type,identifier,value){
		switch(type){
			case "text":
			case "textbox":
				_typeText(identifier,value);
				break;
			case "button":
				_typeText(identifier,value);
				break;
		}


	}

	function _typeText(idNameClassOrValue,valueToType){
		var obj=null;
		var found=$("#"+idNameClassOrValue).length>0;
		if(!found){
			obj=$('[name="' + idNameClassOrValue + '"]');
			found=obj.length>0; 
		}
		if(!found){
			obj=$('[value="' + idNameClassOrValue + '"]'); 
			found=obj.length>0; 
		}
		if(!found){
			obj=$('[class="' + idNameClassOrValue + '"]'); 
			found=obj.length>0; 
		}
		if(found){
			obj.val(valueToType);
		}
	}

	function _buttonClick(idNameClassOrValue,valueToType){
		var obj=null;
		var found=$("#"+idNameClassOrValue).length>0;
		if(!found){
			obj=$('[name="' + idNameClassOrValue + '"]');
			found=obj.length>0; 
		}
		if(!found){
			obj=$('[value="' + idNameClassOrValue + '"]'); 
			found=obj.length>0; 
		}
		if(!found){
			obj=$('[class="' + idNameClassOrValue + '"]'); 
			found=obj.length>0; 
		}
		if(found){
			obj.click();
		}
	}




	function _getHtmlTextBoxes(){
		var i=0;
		$(':text').each(function() { 
			var obj=$(this);
			_listOfElements[i]=obj;
			i++;

		});

	}


	function _getElementByIndex(index){
		return _listOfElements[index];
	}

	function _addTestLine(line){


	}


return {

        Init: function() {
            _init();
        },
		AddTestLine: function(line) {
            _addTestLine(line);
        }
    };
} ();

Intercept.Init();


		
		 
		// Check if jQuery's loaded
		
		
		 
		// All your GM code must be inside this function
		
	 